package com.example.ovulationperiodtracker.Allactivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;

import com.example.ovulationperiodtracker.MyApplication;
import com.example.ovulationperiodtracker.databinding.ActivitySplashBinding;
import com.example.ovulationperiodtracker.utils.Constants;
import com.example.ovulationperiodtracker.view.NoteUtils;
import com.example.ovulationperiodtracker.view.YsDialog;
import com.necer.base.BaseActivity;
import com.tencent.mmkv.MMKV;


public class SplashActivity extends BaseActivity<ActivitySplashBinding> {

    private final MMKV mmkv = MMKV.defaultMMKV();

    @SuppressLint("MissingSuperCall")
    @Override
    public void onBackPressed() {
        // super.onBackPressed();
    }

    @Override
    public ActivitySplashBinding createBinding(LayoutInflater inflater) {
        return ActivitySplashBinding.inflate(inflater);
    }

    @Override
    public void onCreated(Bundle savedInstanceState) {
        boolean firstIn = mmkv.decodeBool(Constants.FIRST_IN, true);
        if (firstIn) {
            new YsDialog(this)
                    .setOnClickYesNoListener(new YsDialog.OnClickYesNoListener() {
                        @Override
                        public void onClickYes() {
                            mmkv.encode(Constants.FIRST_IN, false);
                            // 用户同意之后再加载友盟
                            MyApplication.initUM();
                            enterApp();
                        }

                        @Override
                        public void onClickNo() {
                            finish();
                        }
                    }).show();
        } else {
            enterApp();
        }
    }

    private void enterApp() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                String pin = NoteUtils.getPin();
                if (!TextUtils.isEmpty(pin)) {
                    startActivity(new Intent(SplashActivity.this, PinActivity.class));
                    finish();
                }else{
                    startActivity(new Intent(SplashActivity.this, MainActivity2.class));
                    finish();
                }
            }
        }, 1000);
    }
}